package com.example.springboot.service;

import com.example.springboot.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 单个数据源测试
 *
 * @author Zhang.Z
 * @version 2025-09-22
 */
@Service
public class SingleService {


    @Autowired
    private JdbcTemplate jdbcTemplate;

    public UserVO findOne(Long id){
        String sql = "select id,user_name username,create_time createTime from `t_user_tab` limit 1";
        List<UserVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UserVO.class));
        if (CollectionUtils.isEmpty(list)) return null;
        return list.get(0);
    }
}
